package com.TeamJigsaw.DanteTrail.Views;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.TeamJigsaw.DanteTrail.Views.Interfaces.TownViewInterface;
import net.miginfocom.swing.MigLayout;

public class TownView extends JPanel implements TownViewInterface{
	
	private JButton btnPartyStatus, btnMap, btnShop, btnRest, btnProceed;
	private JLabel lblNewLabel, lblImage;
	private JButton btnWagon;
	private String htmlStart, htmlEnd;
	public TownView()
	{
		setSize(new Dimension(700,700));
		setLayout(new MigLayout("", "[100:100:100][100:100:100][][30:30:30][][30:30:30][][30:30:30][][grow][50:50:50]", "[30:30:30][30:30:30][30:30:30][150:150:150][150:150:150][30:30:30][30:30:30]"));
		
		htmlStart = "<html><font size=\"4\" color=\"#FFFFFF\"><b>";
		htmlEnd = "</b></font></html>";
		
		
		initialize();
	}
	
	public void initialize()
	{
		JLabel lblPlayerStatus = new JLabel(htmlStart+"Player Status:"+htmlEnd);
		add(lblPlayerStatus, "cell 1 1");
		
		lblNewLabel = new JLabel("New label");
		add(lblNewLabel, "cell 2 1");
		
		btnMap = new JButton("Map");
		add(btnMap, "cell 4 1");
		
		btnPartyStatus = new JButton("Party Info");
		add(btnPartyStatus, "cell 6 1");
		
		btnWagon = new JButton("Wagon");
		add(btnWagon, "cell 8 1");
		
		lblImage = new JLabel(htmlStart+"image"+htmlEnd);
		add(lblImage, "cell 2 3 8 2,grow");
		
		btnShop = new JButton("Shop");
		add(btnShop, "cell 1 6,grow");
		
		btnRest = new JButton("Rest");
		add(btnRest, "cell 4 6 2 1,grow");
		
		btnProceed = new JButton("Proceed");
		add(btnProceed, "cell 7 6 2 1,grow");
	}

	@Override
	public void setMapButtonListener(ActionListener listen) {
		btnMap.addActionListener(listen);
		
	}

	@Override
	public void setRestButtonListener(ActionListener listen) {
		btnRest.addActionListener(listen);
		
	}

	@Override
	public void setShopButtonListener(ActionListener listen) {
		btnShop.addActionListener(listen);
		
	}

	@Override
	public void setPartyInfoButtonListener(ActionListener listen) {
		btnPartyStatus.addActionListener(listen);
		
	}

	@Override
	public void setProceedButtonListener(ActionListener listen) {
		btnProceed.addActionListener(listen);
		
	}
	
	@Override
	public void setWagonButtonListener(ActionListener listen) {
		btnWagon.addActionListener(listen);
		
	}

	@Override
	public void setStatus(String status) {
		lblNewLabel.setText(htmlStart+status+htmlEnd);
		
	}

	@Override
	public void setImage(ImageIcon image) {
		this.remove(lblImage);
		
		lblImage = new JLabel(image);
		
		add(lblImage, "cell 1 3 8 2,grow");
		
	}
	
	@Override
	public boolean listenersExist() {
		if(btnProceed.getActionListeners().length > 0)
			return true;
		
		return false;
	}

	@Override
	public void removeListeners() {
		if(btnPartyStatus.getActionListeners().length > 0){
			btnPartyStatus.removeActionListener(btnPartyStatus.getActionListeners()[0]);
		}
		if(btnMap.getActionListeners().length > 0){
			btnMap.removeActionListener(btnMap.getActionListeners()[0]);
		}
		if(btnShop.getActionListeners().length > 0){
			btnShop.removeActionListener(btnShop.getActionListeners()[0]);
		}
		if(btnRest.getActionListeners().length > 0){
			btnRest.removeActionListener(btnRest.getActionListeners()[0]);
		}
		if(btnProceed.getActionListeners().length > 0){
			btnProceed.removeActionListener(btnProceed.getActionListeners()[0]);
		}
		
	}
	
	@Override
	public void paintComponent(Graphics g) {
		ImageIcon img = new ImageIcon("resources\\stone_texture.png");
	    g.drawImage(img.getImage(), 0, 0, null);
	  }
}
